﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace CDTM.Modules.TraCuuDiem.Components
{
    public partial class Log
    {
        public List<LogDetail> LogDetails { set; get; }

        public static int DeleteLogDynamic(string whereCondition)
        {
            const string spName = "[dbo].[p_CDTM_Log_DeleteDynamic]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------
        public static List<Log> SelectCollectionDetailsAll()
        {
            List<Log> collection = new List<Log>();

            collection = SelectCollectionAll();

            foreach (Log item in collection)
            {
                item.LogDetails = LogDetail.SelectCollectionDynamic("LogID = " + item.LogID, "");
            }

            return collection;
        }

        //---------------------------------------------------------------------------------------------

        public static List<Log> SelectCollectionDetailsDynamic(string whereCondition, string orderByExpression)
        {
            List<Log> collection = new List<Log>();

            collection = SelectCollectionDynamic(whereCondition, orderByExpression);

            foreach (Log item in collection)
            {
                item.LogDetails = LogDetail.SelectCollectionDynamic("LogID = " + item.LogID, "");
            }

            return collection;
        }

    }
}
